home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / demos / plasma_globaltrash / plasma.s < prev    next >
Text File  |  1980-01-03  |  12KB  |  529 lines

  1. ***********************************************************
  2. * This is the plasma routine from the Silents demo
  3. * "Global Trash".  The original version of this code, which
  4. * should be included in this archive, was send to me via
  5. * e-mail by Mattias Myrberg (m92mmy@megrez.tdb.uu.se).
  6. *
  7. * The version of the source that you are now looking at was
  8. * fixed up (and optimized a little bit) by the Dancing Fool
  9. * of Epsilon.
  10. ***********************************************************
  11. * Includes
  12. ***********************************************************
  13. ;        opt    o+,c+,w-,p-,a-
  14.         
  15.         incdir    "includes:"
  16.         include    "exec/execbase.i"
  17.         include    "graphics/gfxbase.i"
  18.         include    "graphics/graphics_lib.i"
  19.         include    "hardware/custom.i"
  20.         include    "exec/exec_lib.i"
  21.         ;incdir    'miscsource:'
  22.  
  23. ***********************************************************
  24. * Other Equates
  25. ***********************************************************
  26.  
  27. ;PAL        equ    0        ; 0 = NTSC, 1 = PAL
  28.  
  29. Bits        equ    352
  30. _Scan        equ    44
  31.  
  32. ;Rasters        equ    263
  33. Rasters        equ    290
  34.  
  35. Bpsize        equ    Rasters*_Scan
  36.  
  37. ***********************************************************
  38. * Other Macros
  39. ***********************************************************
  40.  
  41. CALL        MACRO
  42.         jsr    _LVO\1(a6)
  43.         ENDM
  44.  
  45. BltWait        Macro                Wait for blitter
  46. Bltbusy\@:    btst.b    #6,2(a6)
  47.         bne.b    Bltbusy\@
  48.         Endm
  49.  
  50. Sync:        Macro                Syncronizise
  51. Rastwait\@    move.l    4(a6),d0
  52.         and.l    #$1ff00,d0
  53.         lsr.l    #8,d0
  54.         cmp.w    #\1,d0
  55.         bne.b    Rastwait\@
  56.         Endm
  57.  
  58. ***********************************************************
  59.  
  60.         Section    Program,code
  61.  
  62. TakeSystem:    movea.l    4.w,a6        ; exec base
  63.         lea    $dff000,a5    ; custom chip base + 2
  64.  
  65.         lea    GfxName(pc),a1    ; "graphics.library"
  66.         moveq    #0,d0        ; any version
  67.         CALL    OpenLibrary    ; open it.
  68.         move.l    d0,gfx_base    ; save pointer to gfx base
  69.         movea.l    d0,a6        ; for later callls...
  70.  
  71.         move.l  gb_ActiView(a6),OldView    ; save old view
  72.  
  73.         move.w    #0,a1        ; clears full long-word
  74.         CALL    LoadView    ; Open a NULL view (resets display
  75.                     ;   on any Amiga)
  76.  
  77.         CALL    WaitTOF        ; Wait twice so that an interlace
  78.         CALL    WaitTOF        ;   display can reset.
  79.  
  80.         CALL    OwnBlitter    ; take over the blitter and...
  81.         CALL    WaitBlit    ;   wait for it to finish so we
  82.                     ;   can safely use it as we please.
  83.  
  84.         movea.l    4.w,a6        ; exec base
  85.         CALL    Forbid        ; kill multitasking
  86.  
  87.         bsr.w    GetVBR        ; get the vector base pointer
  88.         move.l    d0,VectorBase    ; save it for later.
  89.  
  90.         move.w    dmaconr(a5),d0    ; old DMACON bits
  91.         ori.w    #$8000,d0    ; or it set bit for restore
  92.         move.w    d0,OldDMACon    ; save it
  93.  
  94.         move.w    intenar(a5),d0    ; old INTEna bits
  95.         ori.w    #$c000,d0    ; or it set bit for restore
  96.         move.w    d0,OldINTEna    ; save it
  97.  
  98.         move.l    #$7fff7fff,intena(a5)    ; kill all ints
  99.         move.w    #$7fff,dmacon(a5)    ; kill all dma
  100.  
  101.         lea    BmapPtrs+2,a0
  102.         move.l    #Screen1,d0
  103.         move.w    d0,4(a0)
  104.         swap    d0
  105.         move.w    d0,(a0)
  106.         move.l    #Screen1+Bpsize,d0
  107.         move.w    d0,12(a0)
  108.         swap    d0
  109.         move.w    d0,8(a0)
  110.         move.l    #Screen1+(Bpsize*2),d0
  111.         move.w    d0,20(a0)
  112.         swap    d0
  113.         move.w    d0,16(a0)
  114.         move.l    #Screen1+(Bpsize*3),d0
  115.         move.w    d0,28(a0)
  116.         swap    d0
  117.         move.w    d0,24(a0)
  118.  
  119.         move.l    VectorBase,a0
  120.         move.l    $6c(a0),OldLevel3
  121.         move.l    #Level3,$6c(a0)
  122.         move.l    #Copperlist,$80(a5)    ; Our Copperlist
  123.         move.w    #0,$88(a5)
  124.         move.w    #$83c0,dmacon(a5)    ; Turn on cop,bitplane,blt
  125.         move.w    #$c020,intena(a5)    ; Allow interrupt
  126.  
  127.         bsr.w    Init            ; Initiation
  128.  
  129.         lea    Pattern1(pc),a6
  130.         bsr.w    Main
  131.         lea    Pattern2(pc),a6
  132.         bsr.w    Main
  133.         lea    Pattern3(pc),a6
  134.         bsr.w    Main
  135.         lea    Pattern4(pc),a6
  136.         bsr.w    Main
  137.         lea    Pattern5(pc),a6
  138.         bsr.w    Main
  139.         lea    Pattern6(pc),a6
  140.         bsr.w    Main
  141.         lea    Pattern7(pc),a6
  142.         bsr.w    Main
  143.         lea    Pattern8(pc),a6
  144.         bsr.w    Main
  145.  
  146. Wait:        btst.b    #6,$bfe001
  147.         bne.b    Wait
  148.  
  149.  
  150. RestoreSystem:    lea    $dff000,a5    ; custom chip base + 2
  151.  
  152.     ; You must do these in this order or you're asking for trouble!
  153.         move.l    #$7fff7fff,intena(a5)    ; kill all ints
  154.         move.w    #$7fff,dmacon(a5)    ; kill all dma
  155.         move.l    VectorBase,a0
  156.         move.l    OldLevel3,$6c(a0)
  157.         move.w    OldDMACon,dmacon(a5)    ; restore old dma bits
  158.         move.w    OldINTEna,intena(a5)    ; restore old int bits
  159.  
  160.         movea.l    OldView,a1    ; old Work Bench view
  161.         movea.l    gfx_base,a6    ; gfx base
  162.         CALL    LoadView    ; Restore the view
  163.         CALL    DisownBlitter    ; give blitter back to the system.
  164.  
  165.         move.l    gb_copinit(a6),$80(a5) ; restore system clist
  166.         movea.l    a6,a1
  167.         movea.l    4.w,a6        ; exec base
  168.         CALL    CloseLibrary
  169.  
  170.     ; there is no call to Permit() because it is implied by the return
  171.     ; to AmigaDOS! :^)
  172.         rts
  173.  
  174. GfxName:    GRAFNAME        ; name of gfx library
  175.         EVEN
  176.  
  177. ***********************************************************
  178.  
  179. Init:        lea    Copper(pc),a0
  180.         lea    Copperlist,a1        ; Copper
  181.  
  182.         move.l    (a0)+,d0
  183. Find_end:    move.l    d0,(a1)+
  184.         move.l    (a0)+,d0
  185.         bne.b    Find_end
  186.  
  187.         lea    6(a1),a0        ; Start of color setting
  188.         move.l    a0,Copcol
  189.         move.w    #Rasters-1,d7        ; No of Copper rasters
  190.         move.l    #$17b1fffe,d0        ; WAIT
  191. Fill_copper:    move.l    d0,(a1)+
  192.         addi.l    #$01000000,d0
  193.         move.l    #$1820000,(a1)+        ; move    
  194.         move.l    #$1840000,(a1)+
  195.         move.l    #$1860000,(a1)+
  196.         move.l    #$1880000,(a1)+
  197.         move.l    #$18a0000,(a1)+
  198.         move.l    #$18c0000,(a1)+
  199.         move.l    #$18e0000,(a1)+
  200.         move.l    #$1900000,(a1)+
  201.         move.l    #$1920000,(a1)+
  202.         move.l    #$1940000,(a1)+
  203.         move.l    #$1960000,(a1)+
  204.         move.l    #$1980000,(a1)+
  205.         move.l    #$19a0000,(a1)+
  206.         move.l    #$19c0000,(a1)+
  207.         move.l    #$19e0000,(a1)+
  208.         dbf    d7,Fill_copper
  209.         moveq    #-2,d7
  210.         move.l    d7,(a1)+
  211.         rts
  212.  
  213. Bit_pointer:    dc.w    0
  214.  
  215. ***********************************************************
  216. * Draw screen
  217. * a6 = pattern
  218.  
  219. Main:        lea    Bitplane0,a0        ; Screen planes
  220.         lea    Bitplane1,a1
  221.         lea    Bitplane2,a2
  222.         lea    Bitplane3,a3
  223.         move.l    (a6)+,a4        ; Bitmaps
  224.         lea    Cosinus(pc),a5        ; Cosinus
  225.         movem.w    (a6)+,d1-d4        ; Start values
  226.  
  227.         move.w    #Rasters-1,d6        ; No of scanlines
  228.         moveq    #7,d0            ; Bit
  229. Next_scan:    move.w    #Bits-1,d7        ; No of bits in one scan
  230.  
  231. Next_bit:    move.b    d0,Bit_pointer        
  232.  
  233.         move.w    (a5,d1.w),d5
  234.         addi.w    #$4000,d5
  235.         lsr.w    #7,d5            ; d5 = Cos(d1)
  236.  
  237.         move.w    (a5,d2.w),d0
  238.         addi.w    #$4000,d0
  239.         lsr.w    #7,d0
  240.         add.w    d0,d5            ; + Cos(d2)
  241.  
  242.         move.w    (a5,d3.w),d0
  243.         addi.w    #$4000,d0
  244.         lsr.w    #7,d0
  245.         add.w    d0,d5            ; + Cos(d3)
  246.  
  247.         move.w    (a5,d4.w),d0
  248.         addi.w    #$4000,d0
  249.         lsr.w    #7,d0
  250.         add.w    d0,d5            ; + Cos(d4)
  251.  
  252.         lsr.w    #1,d5
  253.         add.w    d5,d5
  254.  
  255. Plot_bit:    move.w    (a4,d5.w),d5        ; d5 = bitmap
  256.         move.b    Bit_pointer(pc),d0
  257.         bclr    d0,(a3)            ; Set or clear bits in all
  258.         btst    #3,d5            ; planes
  259.         beq.b    Plane2
  260.         bset    d0,(a3)
  261.  
  262. Plane2:        bclr    d0,(a2)
  263.         btst    #2,d5
  264.         beq.b    Plane1
  265.         bset    d0,(a2)
  266.  
  267. Plane1:        bclr    d0,(a1)
  268.         btst    #1,d5
  269.         beq.b    Plane0
  270.         bset    d0,(a1)
  271.  
  272. Plane0:        bclr    d0,(a0)
  273.         btst    #0,d5
  274.         beq.b    Ready
  275.         bset    d0,(a0)
  276.  
  277. Ready:        subq.b    #1,d0
  278.         bpl.b    No_underflow
  279.  
  280.         addq.b    #8,d0            ; Perform calculations
  281.         addq.w    #1,a0            ; on bit #7
  282.         addq.w    #1,a1            ; in next byte
  283.         addq.w    #1,a2
  284.         addq.w    #1,a3
  285.  
  286. No_underflow:    add.w    (a6),d1
  287.         add.w    2(a6),d2
  288.         add.w    4(a6),d3
  289.         add.w    6(a6),d4
  290.  
  291.         move.w    #$1ffe,d5
  292.         and.w    d5,d1
  293.         and.w    d5,d2
  294.         and.w    d5,d3
  295.         and.w    d5,d4
  296.         dbf    d7,Next_bit
  297.  
  298.         sub.w    8(a6),d1
  299.         sub.w    10(a6),d2
  300.         sub.w    12(a6),d3
  301.         sub.w    14(a6),d4
  302.         and.w    d5,d1
  303.         and.w    d5,d2
  304.         and.w    d5,d3
  305.         and.w    d5,d4
  306.         dbf    d6,Next_scan
  307.         rts
  308.  
  309. ***********************************************************
  310.  
  311. Level3:        movem.l    d0-a6,-(sp)
  312.  
  313.         lea    $dff000,a6
  314.         move.w    #$8400,$96(a6)
  315.         movea.l    Copcol(pc),a0        ; Copper
  316.         lea    Cosinus(pc),a1
  317.         move.l    #Area,d3
  318.         move.w    #$1ffe,d0
  319.         move.w    #$4000,d1
  320.         moveq    #15-1,d7        ; 16 colors
  321.  
  322.         movem.w    Rgb(pc),d4-d6
  323.         addi.w    #20,d4
  324.         addi.w    #26,d5
  325.         addi.w    #-30,d6
  326.         and.w    d0,d4
  327.         and.w    d0,d5
  328.         and.w    d0,d6
  329.         movem.w    d4-d6,Rgb
  330.  
  331. Next_colreg:    addi.w    #36,d4
  332.         addi.w    #-30,d5
  333.         addi.w    #24,d6
  334.         and.w    d0,d4            ; 0-8192
  335.         and.w    d0,d5
  336.         and.w    d0,d6
  337.         movea.l    d3,a2
  338.         movea.l    d3,a3
  339.         movea.l    d3,a4
  340.  
  341.         move.w    (a1,d4.w),d2
  342.         add.w    d1,d2
  343.         lsr.w    #7,d2
  344.         add.w    d2,d2            ; d2 = 0-512
  345.         adda.w    d2,a2
  346.  
  347.         move.w    (a1,d5.w),d2
  348.         add.w    d1,d2
  349.         lsr.w    #7,d2
  350.         add.w    d2,d2
  351.         adda.w    d2,a3
  352.  
  353.         move.w    (a1,d6.w),d2
  354.         add.w    d1,d2
  355.         lsr.w    #7,d2
  356.         add.w    d2,d2
  357.         adda.w    d2,a4
  358.  
  359.         bsr    BlitWait
  360.         move.l    #$8ffe4000,$40(a6)    ; D=(A+8)+(B+4)+C
  361.         move.l    #-1,$44(a6)
  362.         move.l    a3,$48(a6)        ; C => red
  363.         move.l    a4,$4c(a6)        ; B => green
  364.         move.l    a2,$50(a6)        ; A => blue
  365.         move.l    a0,$54(a6)        ; D => copper
  366.         move.l    #0,$60(a6)        ; Mod A,B,C = 0
  367.         move.l    #62,$64(a6)        ; Mod D = 62
  368.         move.w    #(Rasters*64)+1,$58(a6)
  369.         addq.w    #4,a0
  370.         dbf    d7,Next_colreg
  371.  
  372.         movem.l    (sp)+,d0-a6
  373.         move.w    #$7fff,$dff09c
  374.         rte
  375. BlitWait    btst    #14,$dff002
  376.         bne.s    BlitWait
  377.         rts
  378.         
  379. ***********************************************************
  380. * This function provides a method of obtaining a pointer to the base of the
  381. * interrupt vector table on all Amigas.  After getting this pointer, use
  382. * the vector address as an offset.  For example, to install a level three
  383. * interrupt you would do the following:
  384. *
  385. *        bsr    _GetVBR
  386. *        move.l    d0,a0
  387. *        move.l    $6c(a0),OldIntSave
  388. *        move.l    #MyIntCode,$6c(a0)
  389. *
  390. ***********************************************************
  391. * Inputs: none
  392. * Output: d0 contains vbr.
  393.  
  394. GetVBR:        move.l    a5,-(sp)        ; save it.
  395.         moveq    #0,d0            ; clear
  396.         movea.l    4.w,a6            ; exec base
  397.         btst.b    #AFB_68010,AttnFlags+1(a6); are we at least a 68010?
  398.         beq.b    .1            ; nope.
  399.         lea.l    vbr_exception(pc),a5    ; addr of function to get VBR
  400.         CALL    Supervisor        ; supervisor state
  401. .1:        move.l    (sp)+,a5        ; restore it.
  402.         rts                ; return
  403.  
  404. vbr_exception:
  405.     ; movec vbr,Xn is a priv. instr.  You must be supervisor to execute!
  406. ;        movec   vbr,d0
  407.     ; many assemblers don't know the VBR, if yours doesn't, then use this
  408.     ; line instead.
  409.         dc.l    $4e7a0801
  410.         rte                ; back to user state code
  411.  
  412. ***********************************************************
  413.  
  414. Copper:        dc.l    $008e1771
  415.         dc.w    $0090
  416.         dc.b    (($17+Rasters)&$ff),$d1
  417.         dc.l    $00920030,$009400d8    ; 46 bytes/raster
  418.         dc.l    $01060000,$01080000,$010a0000
  419.         dc.l    $01fc0000
  420. BmapPtrs:    dc.l    $00e00000,$00e20000,$00e40000,$00e60000
  421.         dc.l    $00e80000,$00ea0000,$00ec0000,$00ee0000
  422. Sprite:        dc.l    $01200000,$01220000,$01240000,$01260000
  423.         dc.l    $01280000,$012a0000,$012c0000,$012e0000
  424.         dc.l    $01300000,$01320000,$01340000,$01360000
  425.         dc.l    $01380000,$013a0000,$013c0000,$013e0000
  426.         dc.l    $01800000
  427.         dc.l    $01004200
  428. Copend:        dc.l    0
  429.  
  430.  
  431. Pattern1:    dc.l    Col1
  432.         dc.w    7616,768,7040,960
  433.         dc.w    8,12,-4,-16
  434.         dc.w    8*Bits+12
  435.         dc.w    12*Bits-16
  436.         dc.w    -4*Bits+24
  437.         dc.w    -16*Bits-20
  438.  
  439. Pattern2:    dc.l    Col1
  440.         dc.w    200,468,2040,196
  441.         dc.w    6,-30,2,16
  442.         dc.w    6*Bits-12
  443.         dc.w    -30*Bits+16
  444.         dc.w    2*Bits-24
  445.         dc.w    16*Bits+20
  446.  
  447. Pattern3:    dc.l    Col1
  448.         dc.w    10,10,10,10
  449.         dc.w    2,8,16,32
  450.         dc.w    2*Bits-2
  451.         dc.w    8*Bits-8
  452.         dc.w    16*Bits-16
  453.         dc.w    32*Bits-32
  454.  
  455. Pattern4:    dc.l    Col1
  456.         dc.w    0,-20,40,-80
  457.         dc.w    2,2,2,2
  458.         dc.w    2*Bits-2
  459.         dc.w    2*Bits-2
  460.         dc.w    2*Bits-2
  461.         dc.w    2*Bits-2
  462.  
  463. Pattern5:    dc.l    Col1
  464.         dc.w    344,-100,346,2
  465.         dc.w    18,-2,58,8
  466.         dc.w    18*Bits-34
  467.         dc.w    -2*Bits-4
  468.         dc.w    58*Bits+24
  469.         dc.w    8*Bits-20
  470.         dc.l    -1
  471.  
  472. Pattern6:    dc.l    Col1
  473.         dc.w    0,0,0,0
  474.         dc.w    8,8,8,8
  475.         dc.w    8*Bits-8
  476.         dc.w    8*Bits+8
  477.         dc.w    8*Bits+8
  478.         dc.w    8*Bits-2
  479.  
  480. Pattern7:    dc.l    Col1
  481.         dc.w    344,-100,346,2
  482.         dc.w    10,-2,28,4
  483.         dc.w    10*Bits-18
  484.         dc.w    -2*Bits-2
  485.         dc.w    28*Bits+12
  486.         dc.w    4*Bits-10
  487.  
  488. Pattern8:    dc.l    Col1
  489.         dc.w    346,102,-368,104
  490.         dc.w    4,6,-32,-78
  491.         dc.w    4*Bits-24
  492.         dc.w    6*Bits+14
  493.         dc.w    -32*Bits-68
  494.         dc.w    -78*Bits-10
  495.  
  496. Copcol:        dc.l    0
  497. Rgb:        ds.w    3
  498. Cosinus:    incbin    'df0:Plasma.dat'
  499.  
  500. ***********************************************************
  501.  
  502.         section    CopperBars,data_c
  503.         incdir    df0:
  504.         include    'CopperBars.i'
  505.  
  506. ***********************************************************
  507.  
  508.         section    OldPointers_and_such,bss
  509.  
  510. gfx_base    ds.l    1        ; pointer to graphics base
  511. OldView        ds.l    1        ; old Work Bench view addr.
  512. VectorBase:    ds.l    1        ; pointer to the Vector Base
  513.  
  514. OldDMACon:    ds.w    1        ; old dmacon bits
  515. OldINTEna:    ds.w    1        ; old intena bits
  516. OldLevel3:    ds.l    1        ; old level 3 int ptr
  517.  
  518. ***********************************************************
  519.  
  520.         section    ScreAndCopper,bss_c
  521.  
  522. Copperlist:    ds.b    64*1024
  523. Screen1:    ds.b    _Scan
  524. Bitplane0    ds.b    Bpsize
  525. Bitplane1    ds.b    Bpsize
  526. Bitplane2    ds.b    Bpsize
  527. Bitplane3    ds.b    Bpsize
  528.         END
  529.